import os
import numpy as np
import h5py
import glob
import cv2
import sys

# input_dir = "basement_0001a/"
input_dir = sys.argv[1]

allpath = []
for filepath in glob.glob(os.path.join(input_dir, '*.h5')):
  allpath.append(filepath)
allpath.sort()

i=1
for imagepath in allpath:
  print(imagepath)
  h5f = h5py.File(imagepath, "r")
  rgb = np.array(h5f['rgb'])
  rgb = np.transpose(rgb, (1, 2, 0))
  depth = np.array(h5f['depth'])

  # print(rgb.shape)
  cv2.imwrite("rgb/frame" + str(i) + ".jpg",rgb)
  cv2.imwrite("depth/frame" + str(i) + ".jpg",depth)
  i=i+1
